<?php
namespace app\index\controller;

use app\index\model\Article as ArticleModel;
use app\index\model\Category as CategoryModel;
use app\common\controller\HomeBase;
use think\Db;


class Index extends HomeBase {


    protected $category_model;
    protected $article_model;


    protected function _initialize() {
        
       // \think\Url::root('index.php'); 

       
        parent::_initialize();
        $this->article_model  = new ArticleModel();
        $this->category_model = new CategoryModel();
      
        $category_level_list  = $this->category_model->getLevelList();

        $this->assign('category_level_list', $category_level_list);  

    }

    public function index($page = 1) {

        $field = 'id,title,cid,introduction,tag,is_good,thumb,content,author,reading,status,publish_time,sort';
        $article_list  = $this->article_model->field($field)->where('status','eq',1)->order('id desc')
            ->paginate(15, false, ['page' => $page])
            ->each(function($item, $key){
            $item['introduction'] =strip_tags($item['content'],'');
            ;
        });
        $getcategoryName = $this->category_model->column('name', 'id');

        return $this->fetch('index', ['article_list' => $article_list,'getcategoryName' => $getcategoryName]);
    }

    /**
     * 获取开源项目
     */
    public function getKai($page = 1)
    {
        $list = Db::name("kai")->where("status=1")->order("id desc")->paginate(15, false, ['page' => $page]);
        return $this->fetch('kai',['list'=>$list]);
    }

}
